﻿using System.IO;
using System.Runtime.Serialization;
using System.Xml;

namespace KnowledgeKiosk
{
    /// <summary>
    /// Provides various utility methods.
    /// </summary>
    public class TestUtils
    {
        /// <summary>
        /// Serializes an object to XML using the DataContractSerializer.
        /// </summary>
        /// <param name="o">The object to serialize.</param>
        /// <returns>A string representation of the XML.</returns>
        public static string SerializeObjectToString(object o)
        {
            var s = new DataContractSerializer(o.GetType());
            string output;
            using (var sw = new StringWriter())
            {
                using (XmlWriter xw = XmlWriter.Create(sw))
                {
                    s.WriteObject(xw, o);
                }
                output = sw.ToString();
            }
            return output;
        }
    }
}